package com.xfunc.appcheck

import android.os.Build
import android.os.Bundle
import android.provider.Settings
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.xfunc.appcheck.databinding.ActivityMainBinding
import com.xfunc.appcheck.testcase.*
import com.xfunc.appcheck.utils.PrivacyUtil

class MainActivity : AppCompatActivity() {
   lateinit var binding:ActivityMainBinding
    @RequiresApi(Build.VERSION_CODES.M)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding =  DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main)
        binding.cbAgree.setOnCheckedChangeListener { compoundButton, b ->
            PrivacyUtil.isAgreePrivacy = b
            updateData()
        }

        binding.cbUseCache.setOnCheckedChangeListener { compoundButton, b ->
            PrivacyUtil.isUseCache = b
            updateData()
        }

        updateData()

    }

    @RequiresApi(Build.VERSION_CODES.M)
    private fun updateData() {
        val getRunningAppProcesses = getRunningAppProcesses(this)
        binding.btnGetRunningAppProcesses.text =
            "getRunningAppProcesses size=${getRunningAppProcesses?.size}"

        val getRecentTasks = getRecentTasks(this)
        binding.btnGetRecentTasks.text = ("getRecentTasks size=${getRecentTasks?.size}")

        val getRunningTasks = getRunningTasks(this)
        binding.btnGetRunningTasks.text = ("getRunningTasks size=${getRunningTasks?.size}")

        val getAllCellInfo = getAllCellInfo(this)
        binding.btnGetAllCellInfo.text = ("getAllCellInfo size=${getAllCellInfo?.size}")

        val getDeviceId = getDeviceId(this)
        binding.btnGetDeviceId.text = ("getDeviceId=$getDeviceId")

        binding.getSimSerialNumber.text = ("getSimSerialNumber=${getSimSerialNumber(this)}")

        val androidId = Settings.System.getString(this.contentResolver, Settings.Secure.ANDROID_ID)
        binding.btnGetIdAndroid.text = ("androidId=$androidId")

        binding.getSSID.text = ("getSSID=${getSSID(this)}")
        binding.getBSSID.text = ("getBSSID=${getBSSID(this)}")
        binding.getMacAddress.text = ("getMacAddress=${getMacAddress(this)}")
        binding.getConfiguredNetworks.text = ("getConfiguredNetworks,size=${getConfiguredNetworks(this)?.size}")

        binding.getSensorList.text = ("getSensorList size=${getSensorList(this)?.size}")
        binding.getImei.text = ("getImei=${getImei(this)}")

        binding.getScanResults.text = "getScanResults size=${getScanResults(this)?.size}"
        binding.getDhcpInfo.text = "getDhcpInfo=${getDhcpInfo(this)}"

        binding.getLastKnownLocation.text = "getLastKnownLocation=${getLastKnownLocation(this)}"

        requestLocationUpdates(this)
        binding.requestLocationUpdates.text = "requestLocationUpdates"
    }

}